<?php
/**
 * 公用功能
 */

class Public_IndexController extends Cms_AdminController {
	/**
	 * 初始化
	 *
	 */
	public function init() {
		parent::init ();
	}
	
	public function indexAction() {
	
	}
	
	/**
	 * 锁屏
	 */
	public function screenlockAction() {
		$DB_AdminSession = new DB_AdminSession ();
		$DB_AdminSession->updateSessionInfoBySid ( $this->AdminSessionInfo ['sid'], array ('lock_screen' => 1 ) );
	}
	
	/**
	 * 登陆锁屏
	 */
	public function loginscreenlockAction() {
		$lock_password = $this->_request->getPost ( 'lock_password' );
		if (empty ( $lock_password )) {
			echo '2';
			exit ();
		}
		
		$DB_Admin = new DB_Admin ();
		$Admin_Info = $DB_Admin->loadInfoByPrimary ( $this->AdminSessionInfo ['uid'] );
		if (md5 ( $lock_password ) != $Admin_Info ['password']) {
			echo '3';
			exit ();
		}
		
		$DB_AdminSession = new DB_AdminSession ();
		$DB_AdminSession->updateSessionInfoBySid ( $this->AdminSessionInfo ['sid'], array ('lock_screen' => 0 ) );
		echo '1';
		exit ();
	}
	
	/**
	 * 添加快捷方式
	 */
	public function addpanelAction() {
		$menuid = $this->_request->getPost ( 'menuid' );
		if (empty ( $menuid )) {
			echo '0';
			exit ();
		}
		
		$DB_Menu = new DB_Menu ();
		$Menu_Info = $DB_Menu->loadInfoByPrimary ( $menuid );
		$name = $Menu_Info ['name'];
		$controller = $Menu_Info ['controller'];
		
		$DB_Admin_Panel = new DB_AdminPanel ();
		$data = array ('menuid' => $menuid, 'uid' => $this->AdminSessionInfo ['uid'], 'name' => $name, 'controller' => $controller, 'datetime' => time () );
		$DB_Admin_Panel->insert ( $data );
		
		$PanelArr = $DB_Admin_Panel->loadList ( '*', "uid={$this->AdminSessionInfo['uid']}" );
		if (is_array ( $PanelArr )) {
			foreach ( $PanelArr as $val ) {
				echo "<span><a onclick='paneladdclass(this);' target='right' href='{$val['controller']}'>{$val['name']}</a> <a class='panel-delete' href='javascript:delete_panel({$val['menuid']});'></a></span>";
			}
		}
		exit ();
	}
	
	/**
	 * 删除快捷方式
	 */
	public function deletepanelAction() {
		$menuid = $this->_request->getPost ( 'menuid' );
		if (empty ( $menuid )) {
			echo '0';
			exit ();
		}
		
		$DB_Admin_Panel = new DB_AdminPanel ();
		$DB_Admin_Panel->delete ( array ('menuid' => $menuid, 'uid' => $this->AdminSessionInfo ['uid'] ) );
		
		$PanelArr = $DB_Admin_Panel->loadList ( '*', "uid={$this->AdminSessionInfo['uid']}" );
		if (is_array ( $PanelArr )) {
			foreach ( $PanelArr as $val ) {
				echo "<span><a onclick='paneladdclass(this);' target='right' href='{$val['controller']}'>{$val['name']}</a> <a class='panel-delete' href='javascript:delete_panel({$val['menuid']});'></a></span>";
			}
		}
		exit ();
	}
	
	/**
	 * 检查新消息
	 */
	public function messageAction() {
		echo '检查新消息,同时保持登录状态.';
		exit ();
	}
}
?>